home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / wired movies and sprites / qtsprites / application files / comapplication.c next >
Encoding:
Text File  |  2000-06-23  |  9.6 KB  |  405 lines

  1. //////////
  2. //
  3. //    File:        ComApplication.c
  4. //
  5. //    Contains:    Application-specific code for basic QuickTime movie display and control.
  6. //                This file is used for BOTH MacOS and Windows.
  7. //
  8. //    Written by:    Tim Monroe
  9. //                Based (heavily!) on the MovieShell code written by Apple DTS.
  10. //
  11. //    Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <12>         12/16/98    rtm        removed all QTVR API calls, so we can remove QTVR.lib from project
  16. //       <11>         04/02/98    rtm        modified for sprites sample
  17. //       <10>         10/23/97    rtm        moved InitializeQTVR to InitApplication, TerminateQTVR to StopApplication
  18. //       <9>         10/13/97    rtm        reworked HandleApplicationMenu to use menu identifiers
  19. //       <8>         09/11/97    rtm        merged MacApplication.c and WinApplication.c into ComApplication.c
  20. //       <7>         08/21/97    rtm        first file for Windows; based on MacApplication.c for Mac sample code
  21. //       <6>         06/04/97    rtm        removed call to QTVRUtils_IsQTVRMovie in InitApplicationWindowObject
  22. //       <5>         02/06/97    rtm        fixed window resizing code
  23. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  24. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  25. //       <2>         11/27/96    rtm        conversion to personal coding style; added preliminary QTVR support
  26. //       <1>         12/21/94    khs        first file
  27. //       
  28. //////////
  29.  
  30. // header files
  31.  
  32. #include "ComApplication.h"
  33. #include "QTSprites.h"
  34.  
  35. // global variables for Macintosh code
  36. #if TARGET_OS_MAC
  37. #endif
  38.  
  39. long                        gMaxMilliSecToUse = 0L;        
  40.     
  41. extern Boolean                gUseBackgroundPicture;
  42.  
  43.  
  44. //////////
  45. //
  46. // InitApplication
  47. // Do any application-specific initialization.
  48. //
  49. // The theStartPhase parameter determines which "phase" of application start-up is executed,
  50. // *before* the MDI frame window is created or *after*. This distinction is relevant only on
  51. // Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.
  52. //
  53. //////////
  54.  
  55. void InitApplication (UInt32 theStartPhase)
  56. {
  57.     // ***do any start-up activities that should occur before the MDI frame window is created
  58.     if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) {
  59.     
  60.         // check to make sure that QuickTime wired sprites are available;
  61.         // we depend on these features  
  62.         if (!QTUtils_HasWiredSprites())
  63.             QuitFramework();
  64.         
  65.     }    // end of kInitAppPhase_BeforeCreateFrameWindow
  66. }
  67.  
  68.  
  69. //////////
  70. //
  71. // StopApplication
  72. // Do any application-specific shut-down.
  73. //
  74. // The theStopPhase parameter determines which "phase" of application shut-down is executed,
  75. // *before* any open movie windows are destroyed or *after*.
  76. //
  77. //////////
  78.  
  79. void StopApplication (UInt32 theStopPhase)
  80. {
  81.     // ***do any shut-down activities that should occur after the movie windows are destroyed
  82.     if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {
  83.     
  84.     }    // end of kStopAppPhase_AfterDestroyWindows
  85. }
  86.  
  87.  
  88. //////////
  89. //
  90. // DoIdle
  91. // Do any processing that can/should occur at idle time.
  92. //
  93. //////////
  94.  
  95. void DoIdle (WindowReference theWindow)
  96. {
  97.     WindowObject         myWindowObject = NULL;
  98.     GrafPtr             mySavedPort;
  99.     
  100.     GetPort(&mySavedPort);
  101.     MacSetPort(GetPortFromWindowReference(theWindow));
  102.     
  103.     myWindowObject = GetWindowObjectFromWindow(theWindow);
  104.     if (myWindowObject != NULL) {
  105.         MovieController        myMC = NULL;
  106.     
  107.         myMC = (**myWindowObject).fController;
  108.         if (myMC != NULL) {
  109.  
  110. #if TARGET_OS_MAC
  111.             // restore the cursor to the arrow
  112.             // if it's outside the front movie window or outside the window's visible region
  113.             if (theWindow == GetFrontMovieWindow()) {
  114.                 Rect    myRect;
  115.                 Point    myPoint;
  116.                 
  117.                 GetMouse(&myPoint);
  118.                 MCGetControllerBoundsRect(myMC, &myRect);
  119.                 if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, GetPortFromWindowReference(theWindow)->visRgn))
  120.                     MacSetCursor(&qd.arrow);
  121.             }
  122. #endif    // TARGET_OS_MAC
  123.         }
  124.     }
  125.     
  126.     // @@@INSERT APPLICATION-SPECIFIC IDLE-TIME FUNCTIONALITY HERE
  127.     
  128.     MacSetPort(mySavedPort);
  129. }
  130.  
  131.  
  132. //////////
  133. //
  134. // DoUpdateWindow
  135. // Update the specified window.
  136. //
  137. //////////
  138.  
  139. void DoUpdateWindow (WindowReference theWindow, Rect *theRefreshArea)
  140. {
  141.     GrafPtr             mySavedPort;
  142.     
  143.     GetPort(&mySavedPort);
  144.     MacSetPort(GetPortFromWindowReference(theWindow));
  145.     
  146.     BeginUpdate(GetPortFromWindowReference(theWindow));
  147.     
  148.     // draw the movie controller and its movie
  149.     MCDoAction(GetMCFromWindow(theWindow), mcActionDraw, theWindow);
  150.     
  151.     EndUpdate(GetPortFromWindowReference(theWindow));
  152.     MacSetPort(mySavedPort);
  153. }
  154.  
  155.  
  156. //////////
  157. //
  158. // HandleContentClick
  159. // Handle mouse button clicks in the specified window.
  160. //
  161. //////////
  162.  
  163. void HandleContentClick (WindowReference theWindow, EventRecord *theEvent)
  164. {
  165. #pragma unused(theEvent)
  166.  
  167.     GrafPtr             mySavedPort;
  168.     
  169.     GetPort(&mySavedPort);
  170.     MacSetPort(GetPortFromWindowReference(theWindow));
  171.     
  172.     // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  173.  
  174.     MacSetPort(mySavedPort);
  175. }
  176.  
  177.  
  178. //////////
  179. //
  180. // HandleApplicationKeyPress
  181. // Handle application-specific key presses.
  182. // Returns true if the key press was handled, false otherwise.
  183. //
  184. //////////
  185.  
  186. Boolean HandleApplicationKeyPress (char theCharCode)
  187. {
  188.     Boolean        isHandled = true;
  189.     
  190.     switch (theCharCode) {
  191.     
  192.         // @@@HANDLE APPLICATION-SPECIFIC KEY PRESSES HERE
  193.  
  194.         default:
  195.             isHandled = false;
  196.             break;
  197.     }
  198.  
  199.     return(isHandled);
  200. }
  201.  
  202.  
  203. #if TARGET_OS_MAC
  204. //////////
  205. //
  206. // CreateMovieWindow
  207. // Create a window to display a movie in.
  208. //
  209. //////////
  210.  
  211. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  212. {
  213.     WindowRef            myWindow;
  214.         
  215.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  216.     return(myWindow);
  217. }
  218. #endif
  219.  
  220.  
  221. //////////
  222. //
  223. // HandleApplicationMenu
  224. // Handle selections in the application's menus.
  225. //
  226. // The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". 
  227. // When called from Windows, theMenuItem is simply the menu item identifier passed to the window proc.
  228. // When called from MacOS, theMenuItem is constructed like this:
  229. //     *high-order 8 bits == the Macintosh menu ID (1 thru 256)
  230. //     *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)
  231. // In this way, we can simplify the menu-handling code. There are, however, some limitations,
  232. // mainly that the menu item identifiers on Windows must be derived from the Mac values. 
  233. //
  234. //////////
  235.  
  236. void HandleApplicationMenu (UInt16 theMenuItem)
  237. {
  238.     switch (theMenuItem) {
  239.         case IDM_MAKE_SPRITE_MOVIE:
  240.             QTSprites_CreateSpritesMovie();
  241.             break;
  242.         case IDM_USE_BACKGROUND_IMAGE:
  243.             gUseBackgroundPicture = !gUseBackgroundPicture;
  244.             break;
  245.         default:
  246.             break;
  247.     } // switch (theMenuItem)
  248. }
  249.  
  250.  
  251. //////////
  252. //
  253. // AdjustApplicationMenus
  254. // Adjust state of items in the application's menus.
  255. //
  256. // Currently, the Mac application has only one app-specific menu ("Test"); you could change that.
  257. //
  258. //////////
  259.  
  260. void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu)
  261. {
  262. #pragma unused(theWindow)
  263.     MenuReference            myMenu;
  264.     
  265. #if TARGET_OS_WIN32
  266.     myMenu = theMenu;
  267. #elif TARGET_OS_MAC
  268.     myMenu = GetMenuHandle(kTestMenu);
  269. #endif
  270.     
  271.     SetMenuItemCheck(myMenu, IDM_USE_BACKGROUND_IMAGE, gUseBackgroundPicture);
  272.     
  273.     // we don't allow creating new files here...
  274. #if TARGET_OS_MAC
  275.     SetMenuItemState(GetMenuHandle(mFile), iNew, kDisableMenuItem);
  276. #endif
  277.     
  278. }
  279.  
  280.  
  281. //////////
  282. //
  283. // DoApplicationEventLoopAction
  284. // Perform any application-specific event loop actions.
  285. //
  286. // Return true to indicate that we've completely handled the event here, false otherwise.
  287. //
  288. //////////
  289.  
  290. Boolean DoApplicationEventLoopAction (EventRecord *theEvent)
  291. {
  292.     Boolean        isHandled = false;
  293.     
  294.     return(isHandled);
  295. }
  296.  
  297.  
  298. //////////
  299. //
  300. // AddControllerFunctionality
  301. // Configure the movie controller.
  302. //
  303. //////////
  304.  
  305. void AddControllerFunctionality (MovieController theMC)
  306. {
  307.     long            myControllerFlags;
  308.     
  309.     // CLUT table use    
  310.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  311.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  312.  
  313.     // enable keyboard event handling    
  314.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  315.     
  316.     // disable drag support
  317.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  318. }
  319.  
  320.  
  321. //////////
  322. //
  323. // InitApplicationWindowObject
  324. // Do any application-specific initialization of the window object.
  325. //
  326. //////////
  327.  
  328. void InitApplicationWindowObject (WindowObject theWindowObject)
  329. {
  330.     ApplicationDataHdl        myAppData = NULL;
  331.  
  332.     if (theWindowObject == NULL)
  333.         return;
  334.         
  335.     myAppData = QTSprites_InitWindowData(theWindowObject);
  336.     (**theWindowObject).fAppData = (Handle)myAppData;
  337.         
  338. }
  339.  
  340.  
  341. //////////
  342. //
  343. // RemoveApplicationWindowObject
  344. // Do any application-specific clean-up of the window object.
  345. //
  346. //////////
  347.  
  348. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  349. {
  350.     if (theWindowObject != NULL)
  351.         QTSprites_DumpWindowData(theWindowObject);
  352.  
  353.     // DoDestroyMovieWindow in MacFramework.c or MovieWndProc in WinFramework.c
  354.     // releases the window object itself
  355. }
  356.  
  357.  
  358. //////////
  359. //
  360. // ApplicationMCActionFilterProc 
  361. // Intercept some mc actions for the movie controller.
  362. //
  363. // NOTE: The theRefCon parameter is a handle to a window object record.
  364. //
  365. //////////
  366.  
  367. PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
  368. {
  369. #pragma unused(theMC, theParams)
  370.  
  371.     Boolean                isHandled = false;
  372.     WindowObject        myWindowObject = NULL;
  373.     
  374.     myWindowObject = (WindowObject)theRefCon;
  375.     if (myWindowObject == NULL)
  376.         return(isHandled);
  377.         
  378.     switch (theAction) {
  379.     
  380.         // handle window resizing
  381.         case mcActionControllerSizeChanged:
  382.             SizeWindowToMovie(myWindowObject);
  383.             break;
  384.  
  385.         // handle idle events
  386.         case mcActionIdle:
  387.             DoIdle((**myWindowObject).fWindow);
  388.             break;
  389.             
  390.         // handle mouse-down events
  391.         case mcActionMouseDown:
  392.             isHandled = QTSprites_HitTestSprites(myWindowObject, (EventRecord *)theParams);
  393.             break;
  394.             
  395.         default:
  396.             break;
  397.             
  398.     }    // switch (theAction)
  399.     
  400.     return(isHandled);    
  401. }
  402.  
  403.  
  404.  
  405.